package com.example.houqin_oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.comment_oa.pojos.rear.Details;
import com.example.comment_oa.pojos.rear.Entrepot;
import com.example.comment_oa.pojos.rear.Pos;
import com.example.comment_oa.pojos_vo.LogisticsVo.EntrepotVo;
import com.example.houqin_oa.mapper.DetailsMapper;
import com.example.houqin_oa.mapper.PosMapper;
import com.example.houqin_oa.service.DetailsService;
import com.example.houqin_oa.service.EntrepotService;
import com.example.houqin_oa.mapper.EntrepotMapper;
import com.example.houqin_oa.service.LossService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author liang
* @description 针对表【entrepot】的数据库操作Service实现
* @createDate 2022-11-23 18:02:33
*/
@Service
public class EntrepotServiceImpl extends ServiceImpl<EntrepotMapper, Entrepot>
    implements EntrepotService{

    @Autowired
    EntrepotMapper entrepotMapper;

    @Autowired
    LossService lossService;

    @Autowired
    DetailsMapper detailsMapper;

    @Autowired
    PosMapper posMapper;

    @Override
    public List<Entrepot> AllEntrepot(Entrepot entrepot) {
        return entrepotMapper.AllEntrepot(entrepot);
    }


    //报损
    @Override
    public boolean Breakage(EntrepotVo entrepotVo) {
        boolean newly = lossService.InsId(entrepotVo);
        boolean change = entrepotMapper.Breakage(entrepotVo);
        if (newly == true && change == true) {
            return true;
        }else {
            return false;
        }

    }

    @Override
    public boolean Overflow(EntrepotVo entrepotVo) {
        return lossService.InsId(entrepotVo);
    }


    @Override
    public boolean addEntrepot(Pos pos) {
        List<Details> det = detailsMapper.allDet(pos);
        det.forEach((i)->{
            Entrepot ent = entrepotMapper.allEnt(i.getEntrepotId());
            if(ent!=null){
                entrepotMapper.upEnt(i);
            }else {
                entrepotMapper.addEnt(i);
            }
            i.setDetailsUnityId(1);
            posMapper.upPos(i);
        });
        return true;
    }
}




